(function() {
	gaf.requires('gaf.Observable');
	/**
	 * The GameService class provides the ability to create long lived objects that live on the
	 * global Game object. This gives them access to the game as a whole and also allows them
	 * to be accessed from anywhere within the game. A good example of a GameService would be 
	 * the main GameLoop class.
	 **/
	gaf.define('gaf.services.GameService', gaf.Observable, {
	    /* -------------------------
		 * 	Properties
		 * ------------------------- */
		/**
		 * If true the service is currently responding to and notifying subscribers of events. This
		 * property should never be changed manually as doing so will not change the service's state
		 * but will create unforseen problems with the service's execution.
		 **/
		isActive: null,
		game: null,
	    /* -------------------------
		 * 	Constructor
		 * ------------------------- */
		constructor: function(game) {
			this.base();
			
			this.isActive = false;
			this.game = game;
		},
	    /* -------------------------
		 * 	Public Methods
		 * ------------------------- */
		/**
		 * Gets the unique id associated with this service. This method must be overwritten by your
		 * implementation of the GameService object and should return a String.
		 **/
		getServiceID: function() {
			return null;
		},
		/**
		 * Starts the service, setting it to active. A service that is not active (isActive == false) will not
		 * recognized by the game when requesting a reference to the service. This method should be overriden
		 * by your service implementation and you must ensure that you call this.base() within your start() method.
		 **/
		start: function() {
			this.isActive = true;
			
			var event = new gaf.events.Event(gaf.services.GameService.Events.SERVICE_STARTED, this, {
				serviceID: this.getServiceID()
			});
			this.notify(event);
		},
		/**
		 * Stops the service, removing it from the list of active services the game will use when the reference 
		 * to a service is requested. This method should be overriden by your service implementation and you must 
		 * ensure that you call this.base() within your stop() method.
		 **/
		stop: function() {
			this.isActive = false;
			
			var event = new gaf.events.Event(gaf.services.GameService.Events.SERVICE_STOPPED, this, {
				serviceID: this.getServiceID()
			});
			this.notify(event);
		},
        /* -------------------------
         * 	Static Properties
         * ------------------------- */
		statics: {
			Events: {
				SERVICE_STARTED: 'serviceStarted',
				SERVICE_STOPPED: 'serviceStopped'
			}
		}
	});
})();
